package cn.school.servlet;

import cn.school.entity.Subject;
import cn.school.service.GradeService;
import cn.school.service.SubjectService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "subjectinfo",urlPatterns = "/12_6/subjectinfo")
public class Subjectinfo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        Object p = request.getParameter("pageNosb");
        int pageNo = 1;
        if(p != null){
            pageNo = Integer.parseInt(p.toString());
        }
        SubjectService ss = new SubjectService();
        List<Subject> list = ss.findALL(pageNo,10);
        int total = ss.total()/10;
        GradeService gs = new GradeService();
        Map<String,String> map = gs.map();
        request.setAttribute("pageNosb",pageNo);
        request.setAttribute("list",list);
        request.setAttribute("map",map);
        request.setAttribute("total",total);
        request.getRequestDispatcher("/12_6/subjectinfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
